<!DOCTYPE html>
<html>
<head>
<title>文件上传</title>
#parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
	<div v-show="showList">
		<div class="grid-btn">
			<a class="btn btn-primary" id="uploadwin"><i class="fa fa-plus"></i>&nbsp;上传文件</a>
			<a class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
			<a class="btn btn-primary" @click="query">刷新</a>
		</div>
	    <table id="jqGrid"></table>
	    <div id="jqGridPager"></div>
    </div>
</div>
<div id="windowupload" hidden="true">
	<div id="preview"></div>
	<form id="uploadForm">
		<input type="file" onchange="preview(this)" name="file" id="uploadFile"/>
		<input type="button" value="上传" onclick="doUpload()" />支持图片预览
	</form>
	<style type="text/css">
		#preview,
		.img,
		img {
			width: 200px;
			height: 200px;
		}

		#preview {
			border: 1px solid #000;
		}
	</style>
	<script type="text/javascript">
        function preview(file) {
            var prevDiv = document.getElementById('preview');
            if (file.files && file.files[0]) {
                var reader = new FileReader();
                reader.onload = function(evt) {
                    prevDiv.innerHTML = '<img src="' + evt.target.result + '" />';
                }
                reader.readAsDataURL(file.files[0]);
            } else {
                prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
            }
        }


        function doUpload() {
            var fileId= utils.getParameter("fileId");

            //alert($("#uploadFile").val());
            var formData = new FormData($( "#uploadForm" )[0]);
            $.ajax({
                url: '../sys/upload/upload?fileId='+fileId ,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function(r){
                    if(r.code === 0){
                        alert('上传成功', function(){
                            //关闭当前窗口页面
                            utils.closeCurrentPage();
                            vm.reload();
                            //刷新父页面
                            //  parent.location.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        }



	</script>
</div>
<script src="${rc.contextPath}/js/sys/upload.js?_${date.systemTime}"></script>
</body>
</html>